﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="SelectVanBan.aspx.cs" Inherits="CMS.Web.CompDenu.SelectVanBan" %>
<script language="javascript" src="Common/util.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Don thu khieu nai to cao</title>
    <link rel="stylesheet" href="../Images/Style.css" />
    
</head>
<body style="margin:0px" class="">
    <form id="form1" runat="server">
            <table id="tblThongTinChung" class="Table_Border" style="border-collapse: collapse"
                cellspacing="0" cellpadding="0" width="100%" border="0">
                <tr>
                    <td class="Text_Main">
                        Danh sách văn bản:</td>
                </tr>
                <tr>
                    <td class="Col_Right">
                        
                        <table  style="border-collapse: collapse" cellspacing="0"
                            cellpadding="0" width="100%" border="0">
                            <tr>
                                <td width="50%">
                                    <asp:ListBox ID="drpVanBan" runat="server" DataTextField="TenVanBan" DataValueField="ID"
                                        Rows="15" CssClass="TextBox" Width="98%" SelectionMode="Multiple"></asp:ListBox></td>
                                <td width="50px">
                                    <table>
                                        <tr>
                                            <td><input type="button" class="Button" style="width:35px" value= ">" onclick="moveRight();" />&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td><input type="button" class="Button"  style="width:35px" value= ">>" onclick="moveAllRight();" />&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td><input type="button" class="Button" style="width:35px" value= "<" onclick="moveLeft();" />&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td><input type="button" class="Button" style="width:35px" value= "<<" onclick="moveAllLeft();" /></td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="49%">
                                    <asp:ListBox ID="drpVBChon" runat="server" 
                                        Rows="15" CssClass="TextBox" Width="98%" SelectionMode=Multiple></asp:ListBox></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr class="Row_Button">
                    <td align="center">
                        <input type="button" class="Button" value="Đồng ý" onclick="selectVanBan();" />
                        <input type="button" class="Button" value="Hủy bỏ" onclick="window.close();" />
                    </td>
                </tr>
            </table>
            
            <script language="javascript" type="text/javascript">
                var drpVanBan = document.getElementById("<%=drpVanBan.ClientID%>");
                var drpVBChon = document.getElementById("<%=drpVBChon.ClientID%>");
                var parentWindow;
                if(window.opener){
                    parentWindow =  window.opener;
                }else{
                    parentWindow = window.dialogArguments;
                }    
                
                window.onload = initSelectedList;
                
                function initSelectedList(){
                    var drpVanBan2 = parentWindow.document.getElementById("<%=ObjId%>");
                    var opt;
                    for(i=0;i<drpVanBan2.options.length;i++){
                        opt = document.createElement("OPTION");
                        drpVBChon.options.add(opt);
                        opt.text = drpVanBan2.options[i].text;
                        opt.value = drpVanBan2.options[i].value;
                    }    
                }
                function changePhongBan_callback(response){
                    if(response!=null && response!=""&&response.value!=null){
                        var vbList = response.value;
                        drpVanBan = document.getElementById("<%=drpVanBan.ClientID %>");
                        for(var i=drpVanBan.options.length-1;i>=0;i--){
                            if(document.all)
                                drpVanBan.options.remove(i);
                            else
                                drpVanBan.remove(i);    
                        }
                        
                        for(var i=0;i<vbList.length;i++){
                           if(!isExistInList(drpVBChon,vbList[i].ID)){
                                var opt = new Option(vbList[i].TenVanBan,vbList[i].ID);
                                drpVanBan.options.add(opt);
                            }
                        }
                    }
                } 
                
                function selectVanBan(){

                    if(window.opener){
                        parentWindow =  window.opener;
                    }else{
                        parentWindow = window.dialogArguments;
                    }    
                    var drpVanBan2 = parentWindow.document.getElementById("<%=ObjId%>");
                    var hidId = parentWindow.document.getElementById("<%=HidId%>");
                    var opt;
                    for(i=drpVanBan2.options.length-1;i>=0;i--){
                        if(document.all)
                            drpVanBan2.options.remove(i);
                        else
                            drpVanBan2.remove(i);  
                    }
                    var Ids = "";
                    for(i=0;i<drpVBChon.options.length;i++){
                        opt = parentWindow.document.createElement("OPTION");
                        drpVanBan2.options.add(opt);
                        opt.text = drpVBChon.options[i].text;
                        opt.value = drpVBChon.options[i].value;
                        Ids += (Ids == "") ? (drpVBChon.options[i].value) : ("," + drpVBChon.options[i].value);
                    }    
                    hidId.value = Ids;
                    window.close();
                }
                function isExistInList(listObj,Id){
                    for(var i=0;i<listObj.options.length;i++){
                        if(listObj.options[i].value == Id) return true;    
                    }
                    return false;
                }
                function moveLeft(){
                    var opt;
                    for(var i=drpVBChon.options.length-1;i>=0;i--){
                        if(drpVBChon.options[i].selected){
                            if(!isExistInList(drpVanBan,drpVBChon.options[i].value)){
                                opt = new Option(drpVBChon.options[i].text,drpVBChon.options[i].value);
                                drpVanBan.options.add(opt);
                            }
                            if(document.all)
                                drpVBChon.options.remove(i);
                            else
                                drpVBChon.remove(i);  
                        }  
                    }
                }
                function moveAllLeft(){
                    var opt;
                    for(i=drpVBChon.options.length-1;i>=0;i--){
                        if(!isExistInList(drpVanBan,drpVBChon.options[i].value)){
                            opt = new Option(drpVBChon.options[i].text,drpVBChon.options[i].value);
                            drpVanBan.options.add(opt);
                        }
                        if(document.all)
                            drpVBChon.options.remove(i);
                        else
                            drpVBChon.remove(i);  
                    }
                }    
                function moveRight(){
                    var opt;
                    for(var i=drpVanBan.options.length-1;i>=0;i--){
                        if(drpVanBan.options[i].selected){
                            if(!isExistInList(drpVBChon,drpVanBan.options[i].value)){
                                opt = new Option(drpVanBan.options[i].text,drpVanBan.options[i].value);
                                drpVBChon.options.add(opt);
                            }
                            if(document.all)
                                drpVanBan.options.remove(i);
                            else
                                drpVanBan.remove(i);  
                        }  
                    }
                }     
                function moveAllRight(){
                    var opt;
                    for(var i=drpVanBan.options.length-1;i>=0;i--){
                        if(!isExistInList(drpVBChon,drpVanBan.options[i].value)){
                            opt = new Option(drpVanBan.options[i].text,drpVanBan.options[i].value);
                            drpVBChon.options.add(opt);
                        }
                        if(document.all)
                            drpVanBan.options.remove(i);
                        else
                            drpVanBan.remove(i);  
                    }
                }        
                function handleEnterKey(e){
                    var isIE = document.all;
                    if(isIE) window.event.returnValue = true;
                    ekeyCode = (isIE)?(window.event.keyCode):(e.which);
                    if (ekeyCode==13){
                        moveRight();
                        if (e.stopPropagation){//Netscape and Firefox 
	                        e.preventDefault();
	                        e.stopPropagation();
                        }
                        return false;
                    }else if(isIE){
                        window.event.returnValue = true;
                    }
                    return true;
                }
                document.onkeydown = function(e){
                    var isIE = document.all;
                    if(isIE) window.event.returnValue = true;
                    ekeyCode = (isIE)?(window.event.keyCode):(e.which);
                    if (ekeyCode==27){
                        window.close();
                        return false;
                    }else if(isIE){
                        window.event.returnValue = true;
                    }
                    return true;
                }
            </script>
    </form>
</body>
</html>
